{extend name="base" /}
{block name="body"}
<div class="layui-card">
	<div class="layui-card-header">
		<form action="{:url('admin/scholarmenuauth/index')}" class="layui-form" method="get">
			<div class="layui-form-item">
				<div class="layui-inline">
					用户
				</div>
				<div class="layui-inline">
					<input type="text" name="name" placeholder="请输入学者/手机" value="{:input('name')}" autocomplete="off" class="layui-input"/>
				</div>
				<!-- <div class="layui-inline">
					手机号码
				</div>
				<div class="layui-inline">
					<input type="text" name="kid" value="{:input('kid')}" autocomplete="off" class="layui-input"/>
				</div> -->
				<div class="layui-inline">
					<button class="layui-btn layui-btn-normal ajax-search"><i class="fa fa-search"></i></button>
					<a onclick="add()" class="layui-btn"><i class="fa fa-plus-circle"></i> 添加学者</a>
				</div>
			</div>
		</form>
	</div>
	<div class="layui-card-body">
		<table class="layui-table layui-form">
			<thead>
			<tr>
				<th>用户</th>
				<th>手机号码</th>
				<th>融合数据仓权限</th>
				<th>学术画像权限</th>
				<th>科技态势感知权限</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			
			{foreach name="list" item="v" empty="$empty"}
			<tr>
				<td>{$v.scholar_name}</td>
				<td>{$v.phone}</td>
				<td>
					
					<!-- fusion_data_warehouse -->
					{if condition="$v.fusion_data_warehouse == 1"}
						<input type="checkbox"  lay-filter="changeStatus" name="fusion_data_warehouse" checked  lay-skin="switch" lay-text="开启|关闭"  value="{$v.id}">
					{else/}
						<input type="checkbox"  lay-filter="changeStatus"  name="fusion_data_warehouse"   lay-skin="switch" lay-text="开启|关闭" value="{$v.id}">
					{/if}
					
				</td>
				<td>
					<!-- academic_portrait -->
					{if condition="$v.academic_portrait == 1"}
						<input type="checkbox"  lay-filter="changeStatus"  name="academic_portrait" checked  lay-skin="switch" lay-text="开启|关闭"  value="{$v.id}">
					{else/}
						<input type="checkbox"  lay-filter="changeStatus"  name="academic_portrait"   lay-skin="switch" lay-text="开启|关闭"  value="{$v.id}">
					{/if}
				</td>
				<td>
					<!-- technology_situation_perceive -->
					{if condition="$v.technology_situation_perceive == 1"}
						
						<input type="checkbox"  lay-filter="changeStatus"  name="technology_situation_perceive" checked  lay-skin="switch" lay-text="开启|关闭"  value="{$v.id}">
					{else/}
						<input type="checkbox"  lay-filter="changeStatus"  name="technology_situation_perceive"   lay-skin="switch" lay-text="开启|关闭"  value="{$v.id}">
					{/if}
				</td>
				<td>
					<a onclick="del({$v.id})" class="layui-btn layui-btn-sm layui-btn-normal"><i class="fa fa-delete"></i> 删除</a>
				</td>
			</tr>
			{/foreach}
			</tbody>
		</table>
		<div class="page">{$list->render()}</div>
	</div>
</div>
{/block}
{block name="js"}
<script>
	// JSON.stringify
	//iframe 层
	layui.use(['form'], function () {
		var form = layui.form;
		form.on('switch(changeStatus)', function (e) {
			var id = e.elem.value
			var name = e.elem.name
			var checked = e.elem.checked
			$.ajax({
				url: '/admin/scholarmenuauth/modifyScholarAuth?id=' + id + '&'+name+'='+(checked?1:0),
				type: 'post',
				success: function (result) {
					if (result.code === 1 && result.url != '') {
						layer.msg('修改成功');
					}
				},
				error: function (xhr, state, errorThrown) {
					layer.msg(state + '：' + errorThrown);
				}
			});
		})
	})

	function add() {
		layer.open({
			type: 2,
			title: '添加学者',
			shadeClose: true,
			shade: false,
			area: ['650px', '600px'],
			content: '/admin/scholarmenuauth/addScholarAuth',
		});
	}
	function del(id){
		layer.confirm('是否删除该学者?', {icon: 3, title:'提示'}, function(index){
			layer.close(index);
			$.ajax({
				url: '/admin/scholarmenuauth/delScholarAuth?id=' + id,
				type: 'post',
				success: function (result) {
					if (result.code === 1 && result.url != '') {
						layer.msg('删除成功');
						location.href = result.url
					}
				},
				error: function (xhr, state, errorThrown) {
					layer.msg(state + '：' + errorThrown);
				}
			});
		});
	}
	
	function multiPush() {
		var userIds = [];
		$('.layui-table tbody input[lay-skin="primary"]:checked').each(function (i) {
			userIds[i] = $(this).val();
		});
		if (userIds === undefined || userIds.length == 0) {
			layer.msg('请选择数据');
			return false;
		}
		layer.open({
			type: 2,
			title: '消息',
			shadeClose: true,
			shade: false,
			area: ['860px', '600px'],
			content: '/admin/push/toPush?userId=' + userIds + '&template=4',
		});
	}
</script>
{/block}